package cn.com.se.sharepictrue.widget;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.AbsListView;

/**
 * Created by KIDNG on 2015/11/24.
 */
public abstract class LoadMoreListener implements AbsListView.OnScrollListener {
    /**
     * 标识剩余几行自动加载
     */
    private int mLoadInLastRow;

    public boolean isLoading() {
        return isLoading;
    }

    public void setLoading(boolean isLoading) {
        this.isLoading = isLoading;
    }

    private boolean isLoading = false;

    public LoadMoreListener(int loadInLastRow) {
        mLoadInLastRow = loadInLastRow;
    }


    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {

    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        int lastVisibleItem = firstVisibleItem + visibleItemCount;
        if (lastVisibleItem >= totalItemCount - mLoadInLastRow) {
            if (!isLoading) {
                isLoading = true;
                load();
            }
        }
    }

    public abstract void load();
}
